from app.services.reques_http import RequestHandler
from flask import Blueprint
from app import app

import json
from common import Common
from flask.json import jsonify
from app.services.JSONResponse import JSONResponse
from flask import request
from app.services.paramRequiredError import Params

bureau_of_education_bp = Blueprint(
    'bureau_of_education', __name__, url_prefix='/' + Common().bureau_of_education)


@bureau_of_education_bp.route('/' + Common().get_many, methods=['POST'])
def index():
    _from = request.args.get("from")
    _size = request.args.get("size")
    print(_from)
    # return "get math"
    # get请求接口
    url = Common().fuwuqiUrl + "/_search"
    # body请求的body
    payload = {
        "from": _from,
        "size": _size,

    }
    res = RequestHandler().get(url=url, params=payload)
    print(res)
    newRes = res.json()['hits']['hits']
    list = []
    for item in newRes:
        list.append(item['_source'])
    return JSONResponse(list)
